﻿namespace ApplicationFrame.EntityFrameworkCore.Core
{
    /// <summary>
    /// 时间分表
    /// </summary>
    [AttributeUsage(AttributeTargets.Class)]
    public class TimeShardingAttribute : Attribute
    {
        /// <summary>
        /// 时间分表类型
        /// </summary>
        public TimeShardingGranularity TimeGranularity { get; }

        /// <summary>
        /// 分表实体属性名称
        /// </summary>
        public string ShardingProperty { get; }

        public TimeShardingAttribute(string shardingProperty, TimeShardingGranularity timeGranularity = TimeShardingGranularity.Month)
        {
            TimeGranularity = timeGranularity;
            if (string.IsNullOrWhiteSpace(shardingProperty))
                throw new ArgumentNullException(nameof(shardingProperty));
            ShardingProperty = shardingProperty;
        }
    }

    /// <summary>
    /// 日间分表枚举
    /// </summary>
    public enum TimeShardingGranularity
    {
        Year = 0,

        Month = 2,

        Day = 4,
    }
}
